package com.gs.study.web;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gs.study.domain.p.User;
import com.gs.study.service.EhcacheService;
import com.gs.study.service.MybatisService;
import com.gs.study.util.BaseController;
import com.gs.study.util.ResultJson;

import net.sf.ehcache.CacheException;

/** 
 * @author gaoshang 
 * @date 创建时间：2018年5月15日 下午4:23:54 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */
@RequestMapping(value="/ehcache")
@Controller
public class EhcacheController extends BaseController{
	private Logger logger = Logger.getLogger(getClass());
	 
	    @Autowired
	    private EhcacheService ehcacheService;
	 
	    @RequestMapping("/encache")
	    public void EhcacheTest(){
	        logger.debug("进行Encache缓存测试");
	        
	        try {
	        System.out.println("====生成第一个用户====");
	        User user1 = new User();
	        //生成第一个用户的唯一标识符 UUID
	        user1.setName("张三");
	        user1.setAge(18);
	        ehcacheService.save(user1);
	        
	 
	        //第一次查询
	        System.out.println(ehcacheService.findByUuid(user1.getId()));
	        //通过缓存查询
	        System.out.println(ehcacheService.findByUuid(user1.getId()));
	 
	        System.out.println("====修改数据====");
	        User user2 = new User();
	        user2.setName("李四-update");
	        user2.setAge(22);
	        user2.setId(user1.getId());
	        user2.setId(user1.getId());
	        System.out.println(ehcacheService.findByUuid(user2.getId()));

	            System.out.println(ehcacheService.update(user2));
	        } catch (Exception e){
	            e.printStackTrace();
	        }
	 
	        ResultJson json=new ResultJson(true);
			printString(json.toString());	    }

	
}
